package com.AAL.DAO;

import java.sql.Date;
import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IPlanDAO;
import com.AAL.Model.Employee;
import com.AAL.Model.Plan;
import com.AAL.Model.StatusOfPlan;
import com.AAL.Utils.HibernateUtil;

public class PlanDAO implements IPlanDAO {

	@Override
	public Plan saveAndUpdatePlan(Plan plan) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(plan);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return plan;
	}

	@Override
	public Plan deletePlan(int planID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			Plan plan = (Plan) session.load(Plan.class, planID);
			if (null != plan) {
				session.delete(plan);
			}
			session.getTransaction().commit();
			return plan;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public Plan getPlan(int planID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Plan plan = (Plan) session.load(Plan.class, planID);
		return plan;
	}

	@Override
	public List<Plan> getLstPlanByEmployee(Employee employee) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Plan> getLstPlanByStatus(StatusOfPlan status) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Plan> getLstPlanByDate(Date date) {
		// TODO Auto-generated method stub
		return null;
	}

}
